/**
 * Created by yudongyang on 2016/2/23 18:13.
 * mail: yudongyang@kehaoinfo.com
 **/

package com.wujie.activies.controller.exchangeBean;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;

import java.util.Collections;
import java.util.List;

/**
 * Created by yudongyang on 2016/2/23.
 * 返回翻页数据的标准格式
 * @see com.wujie.activies.controller.exchangeBean.JSONData
 */
public class JSONPageData {
    private long pages;
    private List data;

    public JSONPageData(List list){
        if(list == null || list.isEmpty()){
            pages = 0;
            data = Collections.EMPTY_LIST;
        }else {
            Page page = (Page)list;
            pages = page.getPages();
            data = list;
        }
    }

    public JSONPageData(Page list){
        pages = list.getTotal();
        if(list.isEmpty()){
            data = Collections.EMPTY_LIST;
        }else {
            data = list;
        }
    }

    public long getPages() {
        return pages;
    }

    public void setPages(long pages) {
        this.pages = pages;
    }

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    @Override
    public String toString(){
        return JSON.toJSONString(this);
    }
}
